package com.daohang361.imqq.pugin.encoder;

import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.protocol.QQ2011;
import com.daohang361.imqq.tool.ByteArray;
import com.daohang361.imqq.tool.Hex2Bytes;
import com.daohang361.imqq.tool.MyByteSendArray;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-22 下午07:37:32 
 * 请求自定义头像 X-FILEHASH x-SIGNSTRING值
 */
public class Encoder0125  implements InterfaceEncoder{
	@Override
	public byte[] encode(QQUser myqq, int c,Object...o) {
		ByteArray myByte = doHead(myqq, "0125");
		myByte.saveThis();//保存此段作为第0段
		myByte.putHex(
				"00 02 01 00 00 00 00 0A"+ 
				"01                     "+
				"04 AF F3 ED            "+
				"01 01                  "+
				"05 AE 98 45            "+
				"01 01                  "+
				"15 C4 41 D0            "+
				"01 01                  "+
				"16 5F 57 BE            "+
				"01 01                  "+
				"1B 6D 40 6E            "+
				"01 01                  "+
				"20 68 B6 06            "+
				"01 01                  "+
				"20 70 A5 36            "+
				"01 01                  "+
				"21 94 0B 03            "+
				"01 01                  "+
				"1C 15 4B 86"			+
				"01 01"					+
				"21 A1 6D 55            "+
				"01                     "		
		);
		myByte.saveThis();//保存此段作为第一段
		myByte.teaThis(1, 1,myqq.getAttr("SessionKey"));//加密第一段到第一段
		System.out.println("SessionKey:"+Hex2Bytes.bytesToHexString(myqq.getAttr("SessionKey")));
		doTail(myByte);
		return myByte.getByteList();//返回完整的package
	}
	
	private boolean ignore=false;
	@Override
	public byte[] encode(QQUser myqq, int c) {
		return null;
	}

	public ByteArray doHead(QQUser myqq,String HexCommand)
	{
		ByteArray myByte = new MyByteSendArray();
		myByte.putInt(QQ2011.QQ_PROTOCOL_PACKAGE_HEAD);
		myByte.putInt(QQ2011.QQ_PROTOCOL_VERSION);
		myByte.putHex(HexCommand);
		myByte.putInt(myqq.getPakage());//包增长应该在接受到此包后
		myByte.putInt(myqq.getQq());
		myByte.putByte(QQ2011.QQ_CONTEX_FIX_12);
		return myByte;
	}
	public ByteArray doTail(ByteArray myByte)
	{
		myByte.putInt(QQ2011.QQ_PROTOCOL_PACKAGE_TAIL);
		myByte.saveThis();//保存此段作为第二段
		return myByte;//返回完整的package
	}
	
	@Override
	public boolean getIgnore() {
		
		return ignore;
	}
	
	@Override
	public void setIgnore(boolean ignore) {
		this.ignore=ignore;
	}
	@Override
	public Object invoke(Object... o) {
	return null;
	}
}
